package club.kingyin.easytoken.config;

import club.kingyin.easytoken.core.EasyToken;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties(EasyTokenProperties.class)
@ConditionalOnClass(EasyToken.class)
public class EasyTokenConfigure {

    @Autowired
    private EasyTokenProperties easyTokenProperties;

    @Bean
    @ConditionalOnMissingBean
    EasyToken easyToken() throws InstantiationException, IllegalAccessException {
        return new EasyToken(easyTokenProperties.getKey(), easyTokenProperties.getPublicKey(), easyTokenProperties.getPrivateKey());
    }
}
